<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>李宁体育管理系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="css/plugins/clockpicker/clockpicker.css" rel="stylesheet">  
    <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">   
  </head>
  <body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>设置查询条件</h5>

                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form role="form" id="queryForm" class="form-inline">
                    	 <div class="form-group">
                            <input class="form-control" type="text" style="width:150px;" id="storeCode" name="storeCode"
                                   value="${map.storeCode}" placeholder="店铺编号"/>
                        </div>
						 <div class="form-group">
                            <input class="form-control" type="text" style="width:150px;" id="name" name="name"
                                   value="${map.name}" placeholder="店铺名"/>
                        </div>
						
                        <div class="form-group">
                            <input class="form-control" type="text" style="width:150px;" id="telephone" name="telephone"
                                   value="${map.telephone}" placeholder="手机号"/>
                        </div>


						<div class="form-group">
							<select data-placeholder="是否VIP" name="isVip"
								style="width: 250px;" class="chosen-select" tabindex="2">
								<option value=""></option>
								<option value="">全部类型</option>
								<option value="0"
									<c:if test="${map.status ==0}">selected</c:if>>非VIP门店</option>
								<option value="1"
									<c:if test="${map.status ==1}">selected</c:if>>VIP门店</option>
							</select>
						</div>


							<div class="input-group">
                            <button class="btn btn-primary" type="button" style="margin-bottom: 0px;"
                                    onclick="search();"><i class="fa fa-search"></i>&nbsp;查询
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- Panel Other -->
    <div class="ibox float-e-margins" id="tableShow">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <table id="ChannelProductListTable" data-mobile-responsive="true"
                               data-click-to-select="true" data-unique-id="id">
                            <thead>
                            </thead>
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->
            </div>
        </div>
    </div>
    <div style="display: none;position: relative;
    top: -50px;" class="modal" id="myModal" tabindex="-1"role="dialog" aria-labelledby="myModalLable" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>--%>
                <h4 class="modal-title" id="myModallabel">消息提示</h4>
            </div>
            <div class="modal-body">
                <span id="deletecontent"></span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirm" onclick="confirm()">确定删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" id="cancel" onclick="cancel()">取消删除</button>

            </div>
        </div>
    </div>
</div>
</div>


<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--时间选择-->
<script src="js/plugins/layer/laydate/laydate.js"></script>
<!--下拉框-->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script>
    var $table = $('#ChannelProductListTable');

    var search = function () {
        $table.bootstrapTable('refresh');
    }
    var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };

    $(document).ready(function () {
        //将表单元素和table属性转成json
        queryParams = function (params) {
            var temp = {};
            temp.currentResult = params.offset;
            temp.showCount = params.limit;
            var formParam = $('#queryForm').serializeArray();
            for (var i = 0; i < formParam.length; i++) {
                if (formParam[i].value != '') {
                    temp[formParam[i].name] = formParam[i].value;
                }
            }
            return temp;
        };




        rowStyle = function (row, index) {
            var classes = ['active', 'success', 'info', 'warning', 'danger'];
            if (index % 2 === 0 && index / 2 < classes.length) {
                return {
                    classes: classes[index / 2]
                };
            }
            return {};
        }

        $table.bootstrapTable({
            url: "store/showStoreList",
            pagination: !0,
            showRefresh: !0,
            showToggle: !0,
            showColumns: !0,
            iconSize: "outline",
            striped: true, //是否显示行间隔色
            queryParams: queryParams,//传递参数（*）
            sidePagination: "server", //服务端处理分页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [5, 10, 20, 50, 'All'],        //可供选择的每页的行数（*）
            minimunCountColumns: 2,      //可供选择的每页的行数（*）
            //detailView: true,
            sortName: undefined,
            sortOrder: 'asc',
            sortStable: false,
            type: "post",
            contentType: "application/json; charset=utf-8",
            rowStyle: rowStyle,
            iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
            icons: {
                refresh: "glyphicon-repeat",
                toggle: "glyphicon-list-alt",
                columns: "glyphicon-list",
                detailOpen: 'glyphicon-plus icon-plus',
                detailClose: 'glyphicon-minus icon-minus',
                sortable: 'glyphicon-minus icon-minus'
            },
            onLoadSuccess: function (data) {
                if (data.total < 5) {
                    $table.bootstrapTable('getOptions')["height"] = 400;
                } else {
                    $table.bootstrapTable('getOptions')["height"] = 800;
                }

                $table.bootstrapTable('hideColumn', 'id');
                $table.bootstrapTable('hideColumn', 'logo');
                $table.bootstrapTable('hideColumn', 'openTime');
                $table.bootstrapTable('hideColumn', 'closeTime');
                $table.bootstrapTable('hideColumn', 'latitude');
                $table.bootstrapTable('hideColumn', 'longitude');
                /* $table.bootstrapTable('hideColumn', 'qrcodeUrl'); */
            },
            columns: [
                {
                    title: '店铺编号',
                    field: 'storeCode',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '店铺名',
                    field: 'name',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '省份',
                    field: 'province',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '城市',
                    field: 'city',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '区域',
                    field: 'district',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '地址',
                    field: 'address',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '手机号',
                    field: 'telephone',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '是否会员门店',
                    field: 'isVip',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                     	if(value==1){
                    		return '<button type="button" onclick="replay('+row.id+','+value+')" class="btn btn-w-m btn-primary">vip门店</button>';
                    	}else if(value==0){
                    		return '<button type="button"  onclick="replay('+row.id+','+value+')" class="btn btn-w-m btn-success">非vip门店</button>';
                    	}
                    }
                },
                {
                    title: '类型',
                    field: 'type',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        if(value==1){
                        	return "维修"
                        }else if(value==2){
                        	return "零售"
                        }else{
                        	return "其他类型"
                        }
                    }
                },
                {
                    title: '商标',
                    field: 'logo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '开店时间',
                    field: 'openTime',
                    align: 'center',
                    valign: 'middle'
                },
             
                {
                    title: '闭店时间',
                    field: 'closeTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '纬度',
                    field: 'latitude',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '经度',
                    field: 'longitude',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '门店二维码',
                    field: 'qrcodeUrl',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (value, row, index) {
                    	if(row.qrcodeUrl != null) {
                    		return "<a href='"+row.qrcodeUrl+"' target='_blank' download='二维码.jpg'><img src='"+row.qrcodeUrl+"' style='width:100px;' /></a>";
                    	} else {
                    		return null;
                    	}
                    }
                },
             /*    {
                    title: '下载二维码',
                    field: 'download',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (value, row, index) {
                 return '<a><button class="btn  btn-xs"  onclick="downloadPic(\''+row.qrcodeUrl+'\')" title="下载二维码"><span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span></button></a>';
                    	
                    }
                }, */
                {
                    title: '信息维护',
                    field: 'operate',
                    align: 'center',
                    width : '140',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                    	var operateStr = '<a><button class="btn  btn-xs" id="editButton" onclick="editproviderDetail(\''+row.id+'\','+index+')" title="维护地址"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></button></a>';
                        if(row.qrcodeUrl == null || row.qrcodeUrl == '') {
                        	operateStr += '<a style="margin-left:5px;"><button class="btn  btn-xs" id="editButton" onclick="createStoreQrcode(\''+row.id+'\')" title="生成门店二维码"><span class="glyphicon glyphicon-qrcode" aria-hidden="true"></span></button></a>';
                        }
						return operateStr;
                    }
                } 
            ]
        });
        for (var selector in config)$(selector).chosen(config[selector]);
    });

    function tableHeight() {
        return $(window).height() - 50;
    }

    
    var editproviderDetail = function (id, index) {
    	var row = $table.bootstrapTable('getRowByUniqueId', id);
    	 window.location.href="<%=basePath%>store/updateStore.do?id="+id; 
    	<%--  window.location.href="<%=basePath%>store/updateStore";  --%>
    }
    
    var createStoreQrcode = function(id) {
    	$.ajax({
    		type:"post",
    		url:"<%=basePath%>store/createStoreQrCode",
    		data:{"storeInfoId":id},
    		success:function(resp) {
    			if(resp.errorCode == "0") {
    				window.location.href="<%=basePath%>store/listStore";
    			} else {
    				alert(resp.errorMsg);
    			}
    		}
    		
    	})
    }

    var archiveForm={};
    var replay =function(id,value){
    	var flage=null;
    	if(value==0){
    		flage=1;
    	}else{
    		flage=0;
    	}
    	 archiveForm['id']=id; 
         archiveForm['isVip']=flage;
    	$.ajax({
            url: "<%=basePath%>store/toUpdateStoreInfo",
            type: "post",
            contentType: "application/json",
		    data: JSON.stringify(archiveForm),
            success: function (note) {
                $table.bootstrapTable('refresh');
            },
            error: function () {
                alert("更改状态异常，请稍后重试");
            }

        });
    }


</script>
  </body>
</html>
